import os
import requests
from datetime import datetime
import json
from PIL import Image
from io import BytesIO

url = 'https://api-inference.modelscope.cn/v1/images/generations'
bozo = os.environ.get("BOZO") + "/Downloads/"
os.chdir(bozo)



img_url = input("请输入需要图片URL地址：\r\n")
tsc = input("请输入修改的英文提示词：\r\n")
# Change the face of this woman into that of a sexy girl.

payload = {
    # 'model': 'bozoyan/FK_FEIFEI',
    'model': 'black-forest-labs/FLUX.1-Kontext-dev',
    'prompt': tsc,
    'image_url': img_url
}


headers = {
    'Authorization': 'Bearer 49f52c59-2173-43c3-ba5d-50d0f1b6d526',
    'Content-Type': 'application/json'
}

response = requests.post(url, data=json.dumps(payload, ensure_ascii=False).encode('utf-8'), headers=headers)

response_data = response.json()
image_url = response_data['images'][0]['url']
image = Image.open(BytesIO(requests.get(image_url).content))

timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"魔搭_{timestamp}.jpg"

print(f"图片URL地址: {image_url}")

image.save(filename)
os.system('open '+ bozo+filename)
